var img = null
var data = null
var scores = null
var counts = 0
var ss = 0
$.getJSON("JSON/yangzhengma.json", function(e) {
    data = e
    console.log(data)
})

function addspicture(e) {

    var htmls = ""

    var suiji = Math.floor(Math.random() * 4)
    console.log("随机数" + suiji)

    htmls += `<img src="yanzheng/${data[suiji].img}" style="width: 100%;height: 100%;"/>`

    scores = data[suiji].number
    console.log("1111:" + scores)
    document.getElementById("imgssss").innerHTML = htmls
}
window.onload = function() {
    addspicture(0)
    var btn = document.getElementById('btn')
    var dianji = document.getElementById("imgssss")
        // console.log("user:" + user + "111")
    dianji.onclick = function() {
        console.log("一点击")
        var htmls = ""

        var suiji = Math.floor(Math.random() * data.length)
        console.log("随机数" + suiji)

        htmls += `<img src="yanzheng/${data[suiji].img}" style="width: 100%;height: 100%;"/>`

        scores = data[suiji].number
        console.log("1111:" + scores)
        document.getElementById("imgssss").innerHTML = htmls
    }
    btn.onclick = function() {
        var tel = document.getElementById('tel').value
        var score = document.getElementById('score').value
        var psd = document.getElementById('psd').value
        var psd1 = document.getElementById('psd1').value
        for (var i = 0; i < localStorage.length; i++) {
            console.log(
                'localStorage里存储的第' +
                i +
                '条数据的名字为：' +
                localStorage.key(i) +
                ',值为：' +
                localStorage.getItem(localStorage.key(i)));
        }
        for (let i = 0; i < localStorage.length; i++) {
            if (localStorage.key(i) == tel) {
                ss = i
                break
            }
        }
        console.log(localStorage.getItem(localStorage.key(ss)))
            // var telt = /^1(3[0-9]|4[01456879]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[0-35-9])\d{8}$/;
        if (localStorage.key(ss) == tel) {
            console.log(score.toLowerCase())
            console.log(scores.toLowerCase())
            if (score.toLowerCase() == scores.toLowerCase()) {
                if (psd == '') {
                    alert('密码不能为空!')
                } else {
                    if (psd == psd1) {
                        localStorage.setItem(tel, psd)
                        window.location = 'z-success.html'
                    } else {
                        alert('输入密码不一致!')
                    }
                }
            } else {
                alert('验证码不正确!')
            }
        } else {
            alert('请输入正确的用户名!')
        }
    }
}